package com.ting.encrypt.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: guohaibing
 * @date: 2022/10/9 13:50
 */
public class ColumnNameUtil {
  public static Pattern compile = Pattern.compile("[A-Z]");

  /**
   * 驼峰转下划线
   *
   * @param str
   * @return
   */
  public static String underlineByhump(String str) {

    Matcher matcher = compile.matcher(str);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
      matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
    }
    matcher.appendTail(sb);
    return sb.toString();
  }

  /**
   * 首字母变小写
   *
   * @param str
   * @return
   */
  public static String lowerFirstCase(String str) {
    char[] chars = str.toCharArray();
    // 首字母小写方法，大写会变成小写，如果小写首字母会消失
    chars[0] += 32;
    return String.valueOf(chars);
  }
}
